using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class AssetManager 
{
    //members
    private Dictionary<string,GameObject> m_assetList;

    #region Instance
    private static AssetManager m_instance;
    private AssetManager() { }
    public static AssetManager Instance
    {
        get
        {
            if (m_instance != null)
                return m_instance;
            else
            {
                m_instance = new AssetManager();
                return m_instance;
            }
        }
    }
    #endregion

    public void Initialize()
    {
        m_assetList = new Dictionary<string, GameObject>();
    }
    public void LoadAssetFromFile(string filePath, string objectName)
    {
        GameObject obj = (GameObject)Resources.LoadAssetAtPath(filePath,typeof(GameObject));
        obj.name = objectName;

        AddAsset(obj);
    }
    public void AddAsset(string name, GameObject obj)
    {
        m_assetList.Add(name, obj);
    }
    public void AddAsset(GameObject obj)
    {
        m_assetList.Add(obj.name,obj);
    }
    public GameObject GetAsset(string name)
    {
        if (m_assetList.ContainsKey(name))
            return m_assetList[name];
        else
            return null;
    }
    public void RemoveAsset(string name)
    {
        if (m_assetList.ContainsKey(name))
            m_assetList.Remove(name);
    }
}
